package edu.ubb.scrumster.model.repository;

import java.util.ArrayList;

import edu.ubb.scrumster.model.model.Comment;
import edu.ubb.scrumster.model.model.AbstractModel;
import edu.ubb.scrumster.model.model.Estimation;
import edu.ubb.scrumster.model.model.User;

public class CommentRepository {

	public CommentRepository() {
	}

	public ArrayList<Comment> getAllComment() {
		ArrayList<Comment> list = new ArrayList<Comment>();
		for (AbstractModel d : DatabaseAccess.getInstance().getAll(DatabaseAccess.COMMENT)){
			list.add(getCommentById(((Comment) d).getId()));
		}
		return list;
	}
	
	public ArrayList<Comment> getCommentByScrum(int id) {
		ArrayList<Comment> list = new ArrayList<Comment>();
		for (AbstractModel d : DatabaseAccess.getInstance().getCommentByScrum(id)){
			list.add(getCommentById(((Comment) d).getId()));
		}
		return list;
	}


	public void addComment(Comment g) {
		DatabaseAccess.getInstance().addData(g);
	}

	public void updateComment(Comment data) {
		DatabaseAccess.getInstance().updateData(data);
	}

	public void deleteComment(Comment data) {
		DatabaseAccess.getInstance().deleteData(data);
	}

	public Comment getCommentById(int id) {
		Comment c= (Comment)DatabaseAccess.getInstance().getDataById(id, DatabaseAccess.COMMENT);
		c.setUser((User)DatabaseAccess.getInstance().getDataById(c.getUser().getId(), DatabaseAccess.USER));
		return c;
	}
}
